package com.woniu05.compartor;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.*;


@Data
@AllArgsConstructor
@NoArgsConstructor
class Person {
    private String name;
    private int age;



    public static void main(String[] args) {
        List<Person> people = new ArrayList<>();
        people.add(new Person("Alice", 25));
        people.add(new Person("Bob", 20));
        people.add(new Person("Charlie", 30));

        // 按年龄升序排序
        Comparator<Person> byAge = new Comparator<Person>() {
            @Override
            public int compare(Person p1, Person p2) {
                return Integer.compare(p1.getAge(),p2.getAge());
            }
        };

        Collections.sort(people, byAge);
        System.out.println("按年龄排序: " + people);
    }


}
